import Router from '@koa/router';
import PermissionController from '@/controllers/PermissionController';
import { auth, requirePermission } from '@/middlewares';
import { PermissionAction } from '@/types';

const router = new Router({
  prefix: '/api/permissions',
});

/**
 * 权限路由
 */

// 获取权限列表
router.get('/', auth, requirePermission('permission', PermissionAction.READ), PermissionController.list.bind(PermissionController));

// 获取资源列表
router.get('/resources', auth, requirePermission('permission', PermissionAction.READ), PermissionController.resources.bind(PermissionController));

// 获取权限详情
router.get('/:id', auth, requirePermission('permission', PermissionAction.READ), PermissionController.detail.bind(PermissionController));

// 创建权限
router.post('/', auth, requirePermission('permission', PermissionAction.CREATE), PermissionController.create.bind(PermissionController));

// 更新权限
router.put('/:id', auth, requirePermission('permission', PermissionAction.UPDATE), PermissionController.update.bind(PermissionController));

// 删除权限
router.delete('/:id', auth, requirePermission('permission', PermissionAction.DELETE), PermissionController.delete.bind(PermissionController));

export default router;

